package com.heima.behavior.service.impl;

import com.heima.behavior.dto.BehaviorDto;
import com.heima.behavior.entity.ApBehaviorEntry;
import com.heima.behavior.entity.ApUnlikesBehavior;
import com.heima.behavior.mapper.ApUnlikesBehaviorMapper;
import com.heima.behavior.service.IApBehaviorEntryService;
import com.heima.behavior.service.IApUnlikesBehaviorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.common.dto.ResponseResult;
import com.heima.common.dto.User;
import com.heima.common.util.UserThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * APP不喜欢行为表 服务实现类
 * </p>
 *
 * @author wangjian
 * @since 2022-07-06
 */
@Service
public class ApUnlikesBehaviorServiceImpl extends ServiceImpl<ApUnlikesBehaviorMapper, ApUnlikesBehavior> implements IApUnlikesBehaviorService {
    @Autowired
    private IApBehaviorEntryService entryService;
    @Override
    public ResponseResult saveUnlikes(BehaviorDto dto) {



            // 获取当前登录的用户
            User user = UserThreadLocalUtil.get();

            ApBehaviorEntry entry = entryService.getEntryByUserIdOrEquipmentId(user.getUserId(),dto.getEquipmentId());
            // 构建不喜欢行为对象
            ApUnlikesBehavior behavior = new ApUnlikesBehavior();
            behavior.setArticleId(dto.getArticleId());
            behavior.setOperation(dto.getOperation());
            behavior.setCreatedTime(new Date());
            this.save(behavior);

            return ResponseResult.okResult();
        }

    }

